home *** CD-ROM | disk | FTP | other *** search
- Path: monkeys.com!not-for-mail
- From: rfg@monkeys.com (Ronald F. Guilmette)
- Newsgroups: comp.std.c
- Subject: Circular buffering for FILEs? Why not?
- Date: 1 Jan 1996 13:03:01 -0800
- Organization: Infinite Monkeys & Co.
- Message-ID: <4c9i65$3b6@segfault.monkeys.com>
- NNTP-Posting-Host: segfault.monkeys.com
-
- I have a question about the traditional implementation of buffered FILEs.
-
- (My apologies to readers of comp.std.c. I know this isn't a question
- which relates directly to the text of the C standard, but I do need to
- put the question to people who are well versed in the details of C imple-
- mentations, and comp.std.c is one likely place to find such people.)
-
- Traditional implementations of getc and putc look pretty much as follows:
-
- ----------------------------------------------------------------------------
- #define getc(p) (--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
- #define putc(x, p) (--(p)->_cnt < 0 ? __flsbuf((unsigned char) (x), (p)) \
- : (int)(*(p)->_ptr++ = (x)))
- ----------------------------------------------------------------------------
-
- The important point to note here is each of these macros causes the
- ``file pointer'' (_ptr) to be incremented... in a very simple-minded
- fashion... whenever a character is taken from, or added to the FILE's
- buffer (respectively).
-
- From this fact I deduce that traditional implementations of the entire
- stdio set of functions _do not_ treat FILE buffers as so-called ``circular
- buffers'' but rather treat them a mere linear buffers.
-
- My question is just this... Why?
-
- Given that traditional implementations of the FILE structure include a
- ``_cnt'' field, it seems to me that it would have been possible... albeit
- at a slight cost... to treat FILE buffers as circular buffers, wraping
- the value of _ptr back to the physical beginning of the buffer each time
- it was seen to have passed the physical end of the buffer. But it seems
- that nobody does this. Why not?
- --
-
- -- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
- ---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
- ------ Copyright (c) 1995 by Ronald F. Guilmette; All rights reserved. -----
-